// JavaScript Document
$(document).ready(function(){
	//解析url参数，获取类型，改变图标样式
	var type = getQueryString('type');
	var key = getQueryString('key');
	if(type==null){
		type='sreach';
	}
    $("#"+type).attr('class',type+'_cli on');
	
	$(".mb ul li button").click(function(){
		var id = $(this).attr('id');
		window.location.href="index.php?m=content&c=index&a=forumdetail&type="+id;
		});
	
 	$(".tcdPageCode").createPage({
        pageCount:pageCount,
        current:1,
        backFn:function(p){
            
            $.ajax({
            	type: "get",
            	url:"index.php?m=content&c=index&a=ajaxdata",
            	dataType:"json",
            	data:{
					page : p,
					type : type,
					key : key
                	},
                success:function(dd){
                	var data = eval(dd);
                	var html = '';
                	for(var i=0; i<data.length;i++){
                		html+='<tr height="60px"><td><a href="'+project+'?mod=viewthread&tid='+data[i].tid+'&extra=page%3D1">'+data[i].subject+'</a></td><td>'+data[i].author+'</td><td>'+data[i].replies+'</td><td>'+data[i].views+'</td><td>'+time_format(data[i].lastpost)+'</td></tr>';                		                	
                	}
                	$('tbody').html(html);
                    },
                error:function(){
					alert("查询错误！");
                    }
                });

        }
    }); 

 	$(".fabuz").click(function(){
 		window.location.href = 	project+"?mod=post&action=newthread&fid="+fid;
 	});
 	
 	$('#sreach').submit(function(){
 		var key = $('#sreach_text').val();
 		if(typeof(key)!='undefined' && key!=''){
 			window.location.href="index.php?m=content&c=index&a=search&key="+key;
 		}else{
 			alert('请不要搜索空值！');
 		}
 		return false;
 	})
});

//获取url参数函数
function getQueryString(name) { 
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
var r = window.location.search.substr(1).match(reg); 
if (r != null) return unescape(r[2]); return null; 
}
//时间戳转换日期函数
function time_format(time) {
	  if (!time)
	    return false;
	  var now, diff, ret, t;
	  // 当前时间戳
	  now = Date.parse(new Date())/1000;
	  // 差值
	  diff = now - time;
	  // 设置时间
	  t = new Date();
	  t.setTime(time*1000);
	  y = t.getFullYear();
	  m = t.getMonth()+1;
	  d = t.getDate();
	  h = t.getHours();
	  i = t.getMinutes();
	  s = t.getSeconds();
	  ret = y+"-"+m+"-"+d+" "+h+":"+i+":"+s;
	  return ret;
	}